package cn.omisheep.autt;

import cn.omisheep.autt.core.Cookies;
import cn.omisheep.commons.util.web.JSONUtils;
import com.fasterxml.jackson.core.type.TypeReference;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;

import java.util.List;
import java.util.Map;

public interface Response {

    String getBody();

    byte[] getBodyBytes();

    default String getBodyPrettyJSON() {
        return JSONUtils.toPrettyJSON(getBody());
    }

    default <T> T getBodyJSONObject(Class<T> cls) {
        return JSONUtils.parseJSON(getBody(), cls);
    }

    default <T> T getBodyJSONObject(TypeReference<T> typeReference) {
        return JSONUtils.parseJSON(getBody(), typeReference);
    }

    default Map<String, Object> getBodyJSONObject() {
        return JSONUtils.parseJSON(getBody(), new TypeReference<Map<String, Object>>() {});
    }

    default Document getBodyDocument() {
        return Jsoup.parse(getBody());
    }

    int getResponseCode();

    Connect getConnect();

    Map<String, List<String>> getHeader();

    String getHeader(String name);

    Cookies getCookies();

    String getCookieVal(String name);

}
